package or.exa.cangguan.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import or.exa.cangguan.common.Result;
import or.exa.cangguan.entity.vo.AreaVo;
import or.exa.cangguan.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "库区管理")
@RestController
public class AreaController {

    @Autowired
    private AreaService areaService;




    @ApiOperation(value = "新增库区")
    @PostMapping("area/add")
    public Result addArea(@RequestBody AreaVo areaVo) {

        int i = areaService.addArea(areaVo);


        return i>0?Result.ok("添加成功"):Result.ok("添加失败");
    }


    //查询库区
    @ApiOperation(value = "查询库区")
    @PostMapping("area/search")
    public Result searchArea(@RequestBody AreaVo areaVo) {


        return Result.ok(areaService.searchArea(areaVo));
    }


    //更新库区
    @ApiOperation(value = "更新库区")
    @PostMapping("area/update")
    public Result updateArea(@RequestBody AreaVo areaVo)
    {

        int i = areaService.updateArea(areaVo);
        return i>0?Result.ok("更新成功"):Result.ok("更新失败");

    }


    @ApiOperation(value = "删除库区")
    @PostMapping("area/delete/{id}")
    //删除库区
    public Result deleteArea(@PathVariable Integer id){
        int i = areaService.deleteArea(id);
        return i>0?Result.ok("删除成功"):Result.ok("删除失败");
    }



    //查询所有库区名称
    @ApiOperation(value = "查询所有库区名称")
    @PostMapping("area/searchName")
    public Result searchAreaName(){
        return Result.ok(areaService.selectName());
    }


}
